
#ifndef __avmplus_avmrt__
#define __avmplus_avmrt__

#ifdef EXPORT
#define DEV_API __declspec(dllexport)
#else
#define DEV_API __declspec(dllimport)
#endif

#ifndef NULL
#define NULL (void*)0
#endif


#ifndef __avmplus_win32_platform__

// Windows doesn't support inttypes.h or most C99 types directly
typedef __int8				int8_t;
typedef __int16				int16_t;
typedef __int32				int32_t;
typedef __int64				int64_t;
typedef unsigned __int8		uint8_t;
typedef unsigned __int16	uint16_t;
typedef unsigned __int32	uint32_t; 
typedef unsigned __int64	uint64_t;

typedef int16_t	wchar;

#endif

#ifndef __avmplus_atom__
typedef int32_t Atom;
#endif

#ifndef __avmplus_atom__
typedef int32_t AvmBox;
#endif

#ifndef __avmplus_MethodEnv__

typedef void ScriptEnv;

#endif

#ifndef __avmplus_VTable__


typedef void VTable;

#endif

#ifndef __avmplus_Multiname__

typedef void Multiname;

#endif

#ifndef __avmplus_ScriptObject__

typedef void ScriptObject;

#endif

#ifndef __avmplus_DomainEnv__
	
typedef void GlobalMemoryProvider;

#endif

#ifndef __avmplus_NewString__
	
typedef void String;

#endif

#ifndef __avmplus_ScriptObject__
	
typedef void ScriptObject;

#endif

struct sMetadataInfo;

typedef sMetadataInfo MetadataInfo;
typedef MetadataInfo* MetadataInfop;

struct sMetadataInfo
{
	char *name;
	char *value;

	MetadataInfop *childs;
};



#ifdef __cplusplus
extern "C" 
{
#endif

#define GC_ZERO 1
#define GC_CONTAINSPOINTERS 2
#define GC_FINALIZE 4
#define GC_RCOBJECT 8
#define GC_CANFAIL 16

/*

	CORE part

*/

DEV_API int avm_init_auto(int api);
DEV_API void avm_shutdown();

DEV_API void avm_throwError( int id, char *err );

DEV_API void avm_atomWriteBarrier( Atom *address, Atom value);
DEV_API void avm_atomWriteBarrier_ctor( Atom *address, Atom value);
DEV_API void avm_atomWriteBarrier_dtor( Atom *address);

/*

	GC part

*/
DEV_API void *avm_gc_alloc(int size,int flags);
DEV_API void avm_gc_free(void *ptr);

DEV_API void *avm_gc_findBeginning(void *ptr);

DEV_API void avm_gc_writeBarrier(const void *address, const void *value);

DEV_API void avm_gc_writeBarrierRC(const void *address, const void *value);
DEV_API void avm_gc_writeBarrierRC_ctor(const void *address, const void *value);
DEV_API void avm_gc_writeBarrierRC_dtor(const void *address);

DEV_API void avm_gc_incrementRef(Atom obj);
DEV_API void avm_gc_decrementRef(Atom obj);

DEV_API void avm_gc_enter( void *pfunc, void *pargs );

/*

	APP part

*/

DEV_API int avm_appmain(char *filename,int argc,char **argv);
DEV_API int avm_dllmain(char *filename, int reason);

DEV_API void avm_exec(char *filename);

DEV_API void avm_abc(char *abc,int size);

DEV_API ScriptEnv* avm_script(char *name,char *abc,int size);
DEV_API MetadataInfop* avm_script_getMetadata( ScriptEnv* script );


DEV_API Atom avm_global_get(char *name);
DEV_API void avm_global_set(char *name,Atom value);

DEV_API Atom avm_global_findDef(char *name);

DEV_API char *avm_atom_toCStr(Atom atom);
DEV_API int avm_atom_toInt(Atom atom);
DEV_API ScriptObject *avm_atom_toObject(Atom atom);

DEV_API void *avm_atom_getDataPointer( Atom obj );


DEV_API int avm_atom_isNull(Atom atom);



DEV_API ScriptObject *avm_Object_getObjectSlot( ScriptObject* obj , int id );
DEV_API void avm_Object_setObjectSlot( ScriptObject* obj ,int id,  ScriptObject* value );



DEV_API Atom avm_Class_construct( Atom cls, int argc, Atom *argv );

DEV_API Atom avm_Object();
DEV_API Atom avm_Buffer(char *bytes, int len );
DEV_API Atom avm_Array( int argc, Atom *argv );
DEV_API Atom avm_Proxy(void *value,void *pget, void *pset, void *pcall, void *pfin);
DEV_API Atom avm_String(char* value,int length);

DEV_API Atom avm_Function_call( Atom obj, int argc, Atom *argv );

DEV_API Atom avm_Object_is(Atom obj,char *name);
DEV_API Atom avm_Object_getAtomProperty(Atom obj,Atom name);
DEV_API Atom avm_Object_getProperty(Atom obj,char *name);

DEV_API void avm_Object_setAtomProperty(Atom obj,Atom name,Atom value);
DEV_API void avm_Object_setProperty(Atom obj,char *name,Atom value);

DEV_API Atom avm_Object_callProperty(Atom obj,char *name,int argc, Atom *argv);
DEV_API Atom avm_Object_callMultinameProperty(Atom obj,char *uri,char *name,int argc, Atom *argv);

DEV_API Atom avm_Array_getItem( Atom obj, int index );
DEV_API void avm_Array_setItem( Atom obj, int index, Atom value );
DEV_API int avm_Array_getLength( Atom obj );

DEV_API Atom avm_Vector_getItem( Atom obj, int index );
DEV_API void avm_Vector_setItem( Atom obj, int index, Atom value );
DEV_API int avm_Vector_getLength( Atom obj );
DEV_API int* avm_Vector_getIntegers( Atom obj );
DEV_API double* avm_Vector_getDoubles( Atom obj  );

DEV_API void* avm_Buffer_getPointer( Atom obj );
DEV_API int avm_Buffer_getLength( Atom obj );

DEV_API Atom avm_intToAtom(int value);
DEV_API Atom avm_uintToAtom(unsigned int value);
DEV_API Atom avm_doubleToAtom(double value);



DEV_API void *avm_Proxy_toVoid(Atom atom);

DEV_API Atom avm_dayToAtom(double year,double month,double date);
DEV_API Atom avm_timeToAtom(double hours,double min,double sec,double msec);
DEV_API Atom avm_dateToAtom(double year,double month,double date,double hours,double min,double sec,double msec);

#ifdef __cplusplus
}
#endif


#endif